low_t=5;
high_t=15;
snip_length=low_t+high_t+1;
all_res={};
cells=[];
cnt2=1;
check={};
for nnd=1:size(all_act{1},1)
    snips={};
    for tnd=1:length(proj_meta(cur_site).ExpGroup)
        raw_act=all_act{tnd}(nnd,:);
        cnt=1;
        ons=find(diff(vis_fl_all{tnd})==1);
        for gnd=1:length(ons)
            if ons(gnd)-low_t>0 && ons(gnd)+high_t<length(vis_fl_all{tnd})
                cur_low=ons(gnd)-low_t:ons(gnd);
                cur_high=ons(gnd)+1:ons(gnd)+high_t;
                if length(unique(shad_all{tnd}(cur_low)))==1 & sum(unique(shad_all{tnd}(cur_low))==0)==1 & length(unique(shad_all{tnd}(cur_high)))==1 & sum(unique(shad_all{tnd}(cur_high))==2)==1
                    check{nnd,tnd}(cnt,:)=[cur_low cur_high];
                    snips{tnd}(cnt,:)=raw_act([cur_low cur_high]);
                    cnt=cnt+1;
                end
            end
        end
    end
    exp_av=[];
    for tnd=1:length(proj_meta(cur_site).ExpGroup)
        if ~isempty(snips{tnd})
            exp_av(tnd,:)=mean(snips{tnd},1);
        else
            exp_av(tnd,:)=0;
        end
    end
    if sum(mean(exp_av(:,1:3),2)*1.05<mean(exp_av(:,snip_length-10:snip_length-8),2))
        cells(cnt2)=nnd;
        for tnd=1:length(proj_meta(cur_site).ExpGroup)
            all_res{tnd}(cnt2,:)=mean(snips{tnd},1);
        end
        cnt2=cnt2+1;
    end
end

for tnd=1:7
    figure;
    set(gcf,'pos',[-1886         534         560         420]+([500 0 0 0]*(tnd-1)))
    imagesc(all_res{tnd})
    set(gca,'clim',[0.8 1.8])
end

figure;
for tnd=1:7
    plot(mean(all_res{tnd},1),'color',[0.8 0.8 0.8]-(0.1*tnd),'linewidth',2)
    hold on
end

mean_res=[];
for tnd=1:7
    mean_res(tnd,1)=mean(mean(all_res{tnd}));
end
figure;plot(mean_res)